﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OOS.Application.Address.Services.Interfaces;
using OOS.Core.Address;

namespace OOS.Application.Address
{
    /// <summary>
    /// 地址管理
    /// </summary>
    [Route("[Controller]")]
    public class AddressBookAppService : IDynamicApiController
    {
        private readonly IAddressBookService _AddressBookService;

        public AddressBookAppService(IAddressBookService addressBookService)
        {
            _AddressBookService = addressBookService;
        }

        /// <summary>
        /// 添加地址
        /// </summary>
        /// <param name="addressBook"></param>
        /// <returns></returns>
        [HttpPost]
        public Boolean AddAddressBook(AddressBook addressBook)
        {
            return _AddressBookService.InsertAddressBook(addressBook);
        }

        /// <summary>
        /// 根据token中的用户id获取地址列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<AddressBook> GetAddressList()
        {
            return _AddressBookService.SelectAddressBooksByUserId();
        }

        /// <summary>
        /// 根据id查询地址详情(原始数据)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public AddressBook GetAddressBook(int id)
        {
            return _AddressBookService.SelectAddressBookById(id);
        }

        /// <summary>
        /// 根据id修改地址
        /// </summary>
        /// <param name="addressBook"></param>
        /// <returns></returns>
        [HttpPut]
        public bool UpdateAddressBook(AddressBook addressBook)
        {
            return _AddressBookService.UpdateAddressBookById(addressBook);
        }

        /// <summary>
        /// 根据id删除地址
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public bool DeleteAddressBook(int id)
        {
            return _AddressBookService.DeleteAddressBookById(id);
        }
    }
}
